from rest_framework import serializers
from .models import Label, Question, Reply
from user.models import User


class UserSimpleSerializers(serializers.ModelSerializer):

    class Meta:
        model = User
        fields = ['id', 'username', 'avatar']


class ReplySerializers(serializers.ModelSerializer):

    user = UserSimpleSerializers(read_only=True)

    class Meta:
        model = Reply
        fields = '__all__'


class QuestionSerializers(serializers.ModelSerializer):
    user = serializers.StringRelatedField()
    labels = serializers.StringRelatedField(many=True, read_only=True)

    class Meta:
        model = Question
        fields = '__all__'


# class LabelSerializers(serializers.ModelSerializer):
#     questions = QuestionSerializers(many=True)
#
#     class Meta:
#         model = Label
#         fields = '__all__'


from article.serializers import ArticleSerializers
class LabelSerializers(serializers.ModelSerializer):
    questions = QuestionSerializers(many=True)
    articles = ArticleSerializers(many=True, read_only=True)


    class Meta:
        model = Label
        fields = '__all__'




